<template>
  <div class="container">
    <el-dialog
      :visible="isShow"
      title="题目预览"
      @close="handleClose"
      @open="handleOpen"
    >
      <el-row>
        <el-col :span="6" class="col"
          >【题型】：{{ question.questionType | qt }}</el-col
        >
        <el-col :span="6" class="col">【编号】：{{ question.id }}</el-col>
        <el-col :span="6" class="col"
          >【难度】：{{ question.difficulty | dc }}</el-col
        >
        <el-col :span="6" class="col">【标签】：{{ question.tags }}</el-col>
        <el-col :span="6" class="col">【学科】：{{ question.subject }}</el-col>
        <el-col :span="6" class="col">【目录】：{{ question.catalog }}</el-col>
        <el-col :span="6" class="col"
          >【方向】：{{ question.direction }}</el-col
        >
      </el-row>
      <hr />
      <!-- 题干 -->
      <p>【题干】：</p>
      <div v-html="question.question" style="color: blue"></div>
      <!-- 单选/多选 -->
      <div v-if="+question.questionType !== 3">
        <div>
          {{ question.questionType | qt }}题 选项：（以下选中的选项为正确答案）
        </div>
        <div
          style="margin-top: 10px"
          v-for="item in questionDetail"
          :key="item.id"
        >
          <el-radio
            v-if="+question.questionType === 1"
            v-model="item.isRight"
            :label="1"
            >{{ item.title }}</el-radio
          >
          <el-checkbox
            v-if="+question.questionType === 2"
            :value="item.isRight ? true : false"
            >{{ item.title }}</el-checkbox
          >
        </div>
      </div>
      <hr />
      【参考答案】：<el-button type="danger" size="mini" @click="play"
        >视频答案预览</el-button
      >
      <div  v-if="isVideoShow">
        <video ref='video' class="video" :src="videoLink" controls></video>
      </div>
      <hr />
      【答案解析】：<div style="display:inline-block" v-html="question.answer"></div>
      <hr />
      【题目备注】：{{question.remarks}}
      <template #footer>
        <el-button @click="handleClose" type="primary">关闭</el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import { questionType, difficulty } from '@/api/hmmm/constants.js'
import { detail } from '@/api/hmmm/questions.js'
export default {
  props: {
    isShow: {
      type: Boolean,
      default: false
    },
    question: {
      type: Object,
      default: () => {}
    }
  },
  data () {
    return {
      questionId: null,
      questionDetail: [],
      isVideoShow: false,
      videoLink: ''
    }
  },
  filters: {
    qt (value) {
      if (value) {
        return questionType.find((item) => item.value === +value).label
      }
    },
    dc (value) {
      if (value) return difficulty.find((item) => item.value === +value).label
    }
  },
  methods: {
    handleClose () {
      this.$emit('update:isShow', false)
      this.isVideoShow = false
    },
    async handleOpen () {
      this.questionId = this.question.id
      // console.log(this.question)
      const {
        data: { options, videoURL }
      } = await detail({ id: this.questionId })
      this.questionDetail = options
      this.videoLink = videoURL
    },
    play () {
      this.isVideoShow = true
      this.$nextTick(() => {
        this.$refs.video.play()
      })
    }
  }
}
</script>

<style scoped lang='scss'>
.col {
  padding: 10px 0;
}
.video {
  margin-top: 30px;
  width: 350px;
  height: 200px;
}
</style>
